package com.lcp.se.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Objects;

/**
 * @author lcp
 * @date 2020/8/6 15:32
 */
@Configuration()
public class ServerInfoConfig {
    private final Logger log = LoggerFactory.getLogger(ServerInfoConfig.class);

    public static String serverInfo;

    @Value("${server.port}")
    private String port;

    @PostConstruct
    public void init() {
        InetAddress localHost = null;
        try {
            localHost = Inet4Address.getLocalHost();
        } catch (UnknownHostException e) {
            log.error(e.getMessage());
        }
        String ip = Objects.requireNonNull(localHost).getHostAddress();
        serverInfo = "im." + ip + "." + port;
        log.info("serverInfo：" + serverInfo);
    }
}
